<?php

include APP_PATH . "Common/Common/lmssky.php";

/**
 * @name 生成验证码
 * @param int $codelen
 * @return null|string
 */
function makeSecurityCode($codelen = 4) {
    $charset = '123456789'; //随机因子
    $securityCode = '';
    $_len = strlen($charset) - 1;
    if ($codelen <= 0)
        return null;
    for ($i = 0; $i < $codelen; $i++) {
        $securityCode .= $charset[mt_rand(0, $_len)];
    }
    return $securityCode;
}

/**
 * @name 获取参数
 * @param string $key
 * @param $default_value
 * @return string
 */
function getParameter($key = '', $default_value = '') {

    if ($key == '')
        return false;
    return I('param.' . $key, $default_value);
}

/**
 *  获取星期一开始和星期天结束的时间戳
 * @return type
 */
function getmonsun() {
    $curtime = strtotime(date('Y-m-d 00:00:00'));

    $curweekday = date('w');

    //为0是 就是 星期七
    $curweekday = $curweekday ? $curweekday : 7;
    $curmon = $curtime - ($curweekday - 1) * 86400;
    $cursun = $curtime + (7 - $curweekday) * 86400 + 86399; //星期天的23:59:59
    $cur['mon'] = $curmon;
    $cur['sun'] = $cursun;
    return $cur;
}

/**
 * 被领取积分算法
 * @param $discount
 * @return int
 */
function getReceiveCredit($discount) {
    $discount = intval($discount);
    if ($discount > 9 || $discount <= 0) {
        return 0;
    }
    $credit = 30 + (9 - $discount) * 10;
    return $credit;
}

/**
 * 优惠卷加解密
 */
function couponEDC($coupon_code, $is_encrypt = true) {

    $aes = new \Common\Utils\aes\Aes();
    $key = "COUPON_CDKEY_2016";
    if ($is_encrypt)
        $coupon_code = $aes->passport_encrypt($coupon_code, $key);
    else
        $coupon_code = $aes->passport_decrypt($coupon_code, $key);
    return $coupon_code;
}

function pushMsg($msg, $mobile) {
    import('Common.Utils.SubmitSms');
    $soap = new SoapClient('http://115.29.52.221:24663/Service/?wsdl');
    $result = $soap->__soapcall('SubmitSms', array(new SubmitSms(
                'llctest001', '123456abc', $mobile, $msg . '【智网科技】' // 这里的签名要替换成用户自己的签名，消息内容要符合已审核模板之一
    )));
    return $result;
}
